package com.minshenglife.zanzan.web.weixin;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.minshenglife.commons.dal.Page;
import com.minshenglife.zanzan.entity.Dept;
import com.minshenglife.zanzan.entity.User;
import com.minshenglife.zanzan.entity.WorkCon;
import com.minshenglife.zanzan.entity.WorkConCom;
import com.minshenglife.zanzan.entity.WorkConMarketPower;
import com.minshenglife.zanzan.entity.WorkConPower;
import com.minshenglife.zanzan.entity.power.EmpPower;
import com.minshenglife.zanzan.entity.power.ManagerEmp;
import com.minshenglife.zanzan.entity.power.TempDept;
import com.minshenglife.zanzan.pub.Keys;
import com.minshenglife.zanzan.pub.utils.Message;
import com.minshenglife.zanzan.pub.utils.PostUtils;
import com.minshenglife.zanzan.result.WorkConComResult;
import com.minshenglife.zanzan.result.WorkConResult;
import com.minshenglife.zanzan.service.AccessTokenService;
import com.minshenglife.zanzan.service.GroupPowerService;
import com.minshenglife.zanzan.service.UserService;
import com.minshenglife.zanzan.service.UserSoftService;
import com.minshenglife.zanzan.service.WorkConComService;
import com.minshenglife.zanzan.service.WorkConMarketPowerService;
import com.minshenglife.zanzan.service.WorkConPowerService;
import com.minshenglife.zanzan.service.WorkConService;
import com.minshenglife.zanzan.service.power.EmpPowerService;
import com.minshenglife.zanzan.service.power.ManagerEmpService;
import com.minshenglife.zanzan.service.power.TempDeptService;
import com.minshenglife.zanzan.service.power.UserRoleService;
import com.minshenglife.zanzan.web.weixin.form.WorkConForm;
import com.minshenglife.zanzan.web.weixin.form.WorkReviewForm;
import com.minshenglife.zanzan.web.weixin.model.UserModel;
import com.nationsky.pub.utils.GsonUtils;
import com.nationsky.pub.utils.StringUtils;

/**
 * 
 * @author huodd
 * 
 */
@Controller
@RequestMapping("/workCon")
public class WorkConController extends BaseController {
	Logger log = LoggerFactory.getLogger(WorkConController.class);
	@Resource
	WorkConService workConService;
	@Resource
	WorkConComService workConComService;
	//add by jianghaibo 2015-02-04
	@Resource
	WorkConPowerService workConPowerService;
	@Resource
	UserService userService;
	@Resource
	AccessTokenService accessTokenService;
	//add by wangpeng 2015-4-17
	@Resource
	TempDeptService tempDeptService;

	@Resource
	UserRoleService userRoleService;
	@Resource
	WorkConMarketPowerService workConMarketPowerService;
	@Resource
	ManagerEmpService managerEmpService;
	@Resource
	GroupPowerService groupPowerService;
	@Resource
	UserSoftService userSoftService;
	
	@Resource
	EmpPowerService empPowerService;

	/** 可以查看他人日志的用户 */
	private final String CANVIEWUSER = "NC_CanViewUser";
	/** 可以审阅他人日志的用户 */
	private final String CANREVIEWUSER = "NC_CanReviewUser";
	/** 可以被审阅的用户 */
	private final String CANBEREVIEWUSER = "NC_CanBeReviewUser";

	private final String NOT_CAN_REVIEW_OTHERS = "对不起，您不具备审阅他人日志的权限";
	private final String NOT_CAN_REVIEW_HIHGER = "对不起，您当前级别为“LEVEL”，无法审阅上级日志";
	private final String NOT_CAN_VIEW_OTHERS = "对不起，您不具备查看他人日志的权限";
	private final String NOT_NC_PERSON = "对不起，您不是一把手日志人员";
	private final String BRANCH_MANAGER_NOT_CAN_COMMENT = "分公司管理员没有发表评论权限";
	/** 总公司员工可以查看分公司日志的用户 */
	private final String CANVIEWUSEROfHO = "HO_CanViewUser";
	/** 总公司员工可以评论分公司日志的用户 */
	private final String CANREVIEWUSEROfHO = "HO_CanReviewUser";
	/** 可以分享他人日志的用户 */
	private final String CANSHAREUSEROfHO = "HO_CanShareUser";

	/**
	 * 添加工作日志
	 * 
	 * @param request
	 * @param response
	 * @param bindForm
	 * @return
	 */
	@RequestMapping(value = "/addOrUpdateCon.do", method = RequestMethod.POST)
	@ResponseBody
	public Message addOrUpdateCon(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			String content = StringUtils.processStrings(conForm.getWorkcon1());
			String logDate = StringUtils.processStrings(conForm.getLogDate());
			String workConType = StringUtils.processStrings(conForm.getWorkConType());
			//校验评论的内容
			if (StringUtils.isNullOrEmpty(logDate)) {
				message = new Message(Message.STATE_one, "工作时间不能为空！");
			} else if (StringUtils.isNullOrEmpty(content)) {
				message = new Message(Message.STATE_one, "工作日志不能为空！");
			} else if (content.getBytes("UTF-8").length >= 3000) {
				message = new Message(Message.STATE_one, "工作日志字符过多，请确认！");
			} else if (StringUtils.isNullOrEmpty(workConType) || (!Keys.WORK_CONTENT_NORMAL.equals(workConType) && !Keys.WORK_CONTENT_MARKETING.equals(workConType)  && !Keys.WORK_CONTENT_RUNNING.equals(workConType) && !Keys.WORK_CONTENT_MANAGER_B.equals(workConType) && !Keys.WORK_CONTENT_FOUNDATION.equals(workConType))) {
				message = new Message(Message.STATE_one, "日志类型错误，请确认！");
			} else {
				User thisUser =userService.getUserInfo(empId);
				//B类不准在A类干部日志里面写日志
				if(workConType.trim().equals(Keys.WORK_CONTENT_NORMAL)&&!StringUtils.isNullOrEmpty(thisUser.getPostId())&&(thisUser.getPostId().trim().toUpperCase().equals("B")||thisUser.getPostId().trim().toUpperCase().equals("C"))){
					message = new Message(Message.STATE_one, "对不起，您没有权限在该日志类型中写日志！");
					return message;
				}
				
				//可以写日志人员放在表t_zz_emp_power_info表中，用于存放某个日志类型的可以审阅和写的人员信息，不是根据部门或级别来区分的。
				// 表中字段：contenttype 日志类型；empid 员工工号；权限 W/R；
				//当contenttype=5即基金会日志时，需要查询是否具有写的权限
				if(workConType.trim().equals(Keys.WORK_CONTENT_FOUNDATION)){
					List<EmpPower> emps = empPowerService.getEmpPowerList(empId, "W", Keys.WORK_CONTENT_FOUNDATION);
					if(emps==null||emps.size()==0){
						message = new Message(Message.STATE_one, "对不起，您没有权限在该日志类型中写日志！");
						return message;
					}
				}
				
				String toWorkConId = conForm.getToWorkConId();
				WorkCon con = new WorkCon();
				if (StringUtils.isNullOrEmpty(toWorkConId) || "null".equals(toWorkConId)) {//新增
					con.setEmpId(empId);
					con.setWorkType(workConType);
					con.setWorkcon1(content);
					con.setLog_date(logDate);
				} else {//修改
					con = workConService.get(Long.parseLong(toWorkConId));
					/*** 修改模式下，需要校验用户是否可以修改该日志；规则：1、两天以内的日志2、日志未被评论或被分享 **/
					if (isCanModify(con)) {
						con.setWorkcon1(content);
						con.setLog_date(logDate);
					} else {
						message = new Message(Message.STATE_one, "对不起，该日志不可以修改！");
					}
				}
				if (message.getState().equals(Message.STATE_200))
					workConService.addOrUpdate(con);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 校验用户是否可以修改该日志；规则：1、两天以内的日志2、日志未被评论或被分享
	 * 
	 * @param con
	 * @return
	 */
	private boolean isCanModify(WorkCon con) {
		boolean bool = true;
		String createTime = con.getCreate_time().substring(0, 10);
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String nowTime = sdf.format(c.getTime());
		log.debug(createTime + "===" + nowTime);
		//校验时间
		if (createTime.compareTo(nowTime) < 0) {
			bool = false;
		}
		//校验日志是否被分享
		else if (Keys.WORK_CONTENT_ISSHARE_YES.equals(con.getIsShare())) {
			bool = false;
		}
		//校验日志是否被评论
		else {
			List<WorkConComResult> list = workConComService.findWorkReviewListOfTop10(con.getId().toString());
			if (list == null || list.size() <= 0 || list.isEmpty()) {
			} else {
				bool = false;
			}
		}
		return bool;
	}

	/**
	 * 是否可以修改工作日志
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/isCanModifyCon.do", method = RequestMethod.POST)
	@ResponseBody
	public Message isCanModifyCon(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);

			WorkCon con = workConService.get(Long.parseLong(conForm.getToWorkConId()));
			if (isCanModify(con)) {
			} else {
				log.debug("当前用户" + empId + "不能修改该日志：" + conForm.getToWorkConId());
				message = new Message(Message.STATE_one, "");
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 是否有查看他人工作日志的权限
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/isCanViewOthers.do", method = RequestMethod.POST)
	@ResponseBody
	public Message isCanViewOthers(HttpServletRequest request, HttpServletResponse response) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			if (isCanView(empId)) {

			} else {
				log.debug("当前用户" + empId + "不具备查看他人日志的权限");
				message = new Message(Message.STATE_one, NOT_CAN_VIEW_OTHERS);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 是否有审阅他人工作日志的权限
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/isCanReViewOthers.do", method = RequestMethod.POST)
	@ResponseBody
	public Message isCanReViewOthers(HttpServletRequest request, HttpServletResponse response) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			if (isCanReview(empId)) {

			} else {
				log.debug("当前用户" + empId + "不具备审阅他人日志的权限");
				message = new Message(Message.STATE_one, NOT_CAN_REVIEW_OTHERS);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 工作内容列表
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/workConList.do", method = RequestMethod.POST)
	@ResponseBody
	public Message workConList(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = null;
		Page<WorkConResult> page;
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			String workConType = conForm.getWorkConType();
			log.debug("请求日志类型：" + workConType);
			/** getToWorkConId 不为空时，则请求他人的日志信息 */
			if (!StringUtils.isNullOrEmpty(conForm.getToWorkConId())) {
				WorkCon con = workConService.get(Long.parseLong(conForm.getToWorkConId()));
				empId = con.getEmpId();
			}
			int pageNo = conForm.getPageNo() == 0 ? 1 : conForm.getPageNo();
			int pageSize = conForm.getPageSize() == 0 ? 10 : conForm.getPageSize();
			page = workConService.findWorkConList(empId, workConType, pageNo, pageSize);
			message = new Message(Message.STATE_200, "", page);
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 查看他人日志列表
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/workConViewList.do", method = RequestMethod.POST)
	@ResponseBody
	public Message workConViewList(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = null;
		Page<WorkConResult> page;
		String empId = super.getEmpId(request);
		log.debug("当前绑定人的empId：" + empId);
		String workConType = conForm.getWorkConType();
		log.debug("请求日志类型：" + workConType);
		int pageNo = conForm.getPageNo() == 0 ? 1 : conForm.getPageNo();
		int pageSize = conForm.getPageSize() == 0 ? 10 : conForm.getPageSize();
		String searchEmp = conForm.getSearchEmp();
		String searchArea = conForm.getSearchArea();
		String searchPost = conForm.getSearchPost();
		//add by jianghaibo 2015-05-22 
		String searchEmpName = conForm.getSearchEmpName();
		String searchConState = conForm.getSearchConState();
		String searchConStartTime = conForm.getSearchConStartTime();
		String searchConEndTime = conForm.getSearchConEndTime();
		String isSearch = conForm.getIsSearch();
		String userPostId = conForm.getUserPostId();
		String viewType = conForm.getViewType();
		searchEmpName = "null".equals(searchEmpName) ? null : searchEmpName;
		searchConState = "null".equals(searchConState) ? null : searchConState;
		searchConStartTime = "null".equals(searchConStartTime) ? null : searchConStartTime;
		searchConEndTime = "null".equals(searchConEndTime) ? null : searchConEndTime;
		
		searchArea = "null".equals(searchArea) ? null : searchArea;
		searchPost = "null".equals(searchPost) ? null : searchPost;
		searchEmp = "null".equals(searchEmp) ? null : searchEmp;
		isSearch = "null".equals(isSearch) ? null : isSearch;
		//查询当前用户信息
		User user = userService.getUserInfo(empId);
		log.info("user info--->"+GsonUtils.toGson(user));
		log.info("user's postId--->"+user.getPostId());
		/*
		Dept dept = userRoleService.getDept(user.getDept_id());
		TempDept tempDept = tempDeptService.findTD(empId);//在临时职位表中是否有信息
		searchArea = dept.getDept_name();//职位总称
		searchPost = user.getPostId();//职级
		if(tempDept != null&&tempDept.getPostId()!= null){
			searchPost = tempDept.getPostId();
		}
		if (tempDept != null&&tempDept.getDept_id()!= null) {//在临时职位保重是否有职位信息
			dept = userRoleService.getDept(tempDept.getDept_id());
			searchArea = dept.getDept_name();
		}
		if(searchPost.equals("S")){
			searchPost = "S";
			searchArea = null;
		}else if(searchArea != null && searchArea.indexOf("责任人") > 0){//如果带有责任人则去掉职位名称 按部门来匹配
			searchArea = searchArea.substring(0, searchArea.lastIndexOf("|"));
			log.info("责任人去掉后面名称：" + searchArea);
		}
		*/
		
		log.info("searchArea=" + searchArea + "searchPost=" + searchPost + "searchEmp=" + searchEmp);
		//add by jianghaibo 2015-05-22
		log.info("searchEmpName=" + searchEmpName + "searchConState=" + searchConState + "searchConStartTime=" + searchConStartTime + "searchConEndTime" + searchConEndTime);
		//一把手日志
		if(Keys.WORK_CONTENT_NORMAL.equals(workConType)){
			String canBeViewedA = "";
			//如果是A类干部日志，先判断用户是否在权限组中拥有对A的审阅权限
			if(viewType.trim().toUpperCase().equals("AZ")){
				canBeViewedA += groupPowerService.findByViewEmpIdAndViewTypeAndPostId(user.getEmpId().trim(), "ZGS","A"); //ZGS 总公司
			}else if(viewType.trim().toUpperCase().equals("AF")){
				canBeViewedA += groupPowerService.findByViewEmpIdAndViewTypeAndPostId(user.getEmpId().trim(), "FGS","A"); //FGS 总公司
			}else{
				canBeViewedA += "";
			}
			
			//针对用户在权限组中是否有权限的判断结果
			boolean flag = true;
			if(canBeViewedA==null||canBeViewedA.trim().length()==0){
				flag = false;
			}else{
				canBeViewedA = canBeViewedA.trim();
			}
			//校验是否具有审阅权限
			if(isCanView(empId)||flag){
//				String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
				//add by jianghaibo 2015-02-04  获取可以被审阅人员列表
				//查询原先的授权规则，查询被审阅的员工
				String canBeReviewUser = "";
				if(isCanView(empId)){
					if(viewType.trim().toUpperCase().equals("AZ")){
						canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER, "ZGS");//ZGS 总公司
					}else if(viewType.trim().toUpperCase().equals("AF")){
						canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER, "FGS");//FGS 分公司
					}else{
						canBeReviewUser = "";
					}
				}
				if(!canBeReviewUser.endsWith("|")){
					canBeReviewUser += "|";
				}
				
				//将两个授权规则的员工合并
				canBeReviewUser += canBeViewedA;
				

				//去重复的工号，由于是根据两种授权规则获得授权方式
				log.info("去重前的被审阅人为："+canBeReviewUser);
				String thisCanBeReviewUser = "";
				String[] viewEmpIds = canBeReviewUser.split("\\|");
				for(int i=0;i<viewEmpIds.length;i++){
					String thisEmpId = viewEmpIds[i];
					if(thisEmpId==null||thisEmpId.equals("null")||thisEmpId.trim().length()==0){
						continue;
					}
					if(thisCanBeReviewUser.contains(thisEmpId)){
						continue;
					}else{
						thisCanBeReviewUser = thisCanBeReviewUser+thisEmpId+"|";
					}
				}
				canBeReviewUser = thisCanBeReviewUser;
				log.info("去重后的被审阅人为："+canBeReviewUser);
				
				if(canBeReviewUser==null||canBeReviewUser.trim().length()==0){
					log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
					message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
					return message;
				}
				
//				page = workConService.findWorkConViewList(canBeReviewUser, pageNo, pageSize,workConType);
				page = workConService.findWorkConViewList(canBeReviewUser, pageNo, pageSize,workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
				message=new Message(Message.STATE_200,"",page);
			}else{
				log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
				message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
			}
		}
		//营销日志
		else if(Keys.WORK_CONTENT_MARKETING.equals(workConType)){
			String nowSearchPost = searchPost;
			//if(searchPost.equals("D")){
			TempDept tempDept = tempDeptService.findTD(empId);//在临时职位表中是否有信息
			
			//如果是拥有分公司管理员权限的员工，无论职级大小，一律拥有A类审阅权限
			if(isBranchManager(user)){
				user.setPostId(User.POSTID_A);
			}
			//通过后台更改日志职级或者职位信息的员工，更改后的日志职级或者职位优先于原来的职级和职位设定。
			else{
				if(tempDept != null && tempDept.getPostId()!= null){
					user.setPostId(tempDept.getPostId());
				}
			}
			//员工所在部门
			Dept dept = null;
			if (tempDept != null && tempDept.getDept_id()!= null) {//在临时职位保重是否有职位信息
				dept = userRoleService.getDept(tempDept.getDept_id());
			}else{
				dept = userRoleService.getDept(user.getDept_id());
			}
			//除总公司S类领导能看所有人外，总、分公司相互独立，不能审阅对方日志。
			//总公司A类能审阅点评自己管辖部门的B、C员工，B类能审阅点评C类员工。
			//分公司A类能审阅点评自己管辖区域B、C、D、E类员工、B类能审阅点评C、D、E类员工、C类能审阅点评D、E类员工；
//			if(dept.getDept_name().indexOf("总公司") != -1 && user.getPostId().equals( User.POSTID_S)){
			if(user.getPostId().equals( User.POSTID_S)){
				if(searchPost != null && !searchPost.equals("")){
					
				}else{
					searchPost =  User.POSTID_S + "," +User.POSTID_A + "," +User.POSTID_B + "," + User.POSTID_C + ","+User.POSTID_D+"," + User.POSTID_E ;
				}
			}else{
				searchArea = dept.getDept_name();
				if(searchArea != null && searchArea.indexOf("责任人") != -1){//如果带有责任人则去掉职位名称 按部门来匹配
					log.info("责任人部门名称：" + searchArea);
					if(searchArea.indexOf("|") != -1){
						searchArea = searchArea.substring(0, searchArea.lastIndexOf("|"));
					}else{
						searchArea = searchArea.substring(0,searchArea.indexOf("责任人"));
					}
					log.info("责任人去掉后面名称：" + searchArea);
				}
				//从搜索页面进行精确搜索
				if(searchPost != null && !searchPost.equals("")){
					
				}
				//点击“我的审阅”
				else{
					//总公司
					if(dept.getDept_name().indexOf("总公司") != -1){
						log.info("该员工为总公司员工"+user.getPostId());
						if(user.getPostId().equals(User.POSTID_A)){
							searchPost = User.POSTID_B + "," + User.POSTID_C ;
						}else if(user.getPostId().equals(User.POSTID_B)){
							searchPost = User.POSTID_C;
						}else if(user.getPostId().equals(User.POSTID_C)){
							searchPost = User.POSTID_D+"," + User.POSTID_E ;
						}
					}
					//分公司
					else{
						log.info("该员工为分公司员工"+user.getPostId());
						if(user.getPostId().equals(User.POSTID_A)){
							searchPost =  User.POSTID_B + "," + User.POSTID_C + ","+User.POSTID_D+"," + User.POSTID_E;
						}else if(user.getPostId().equals(User.POSTID_B)){
							searchPost =  User.POSTID_C + ","+User.POSTID_D+"," + User.POSTID_E ;
						}else if(user.getPostId().equals(User.POSTID_C)){
							searchPost = User.POSTID_D+"," + User.POSTID_E ;
						}
					}
				}
			}
			//----------------------------------------------------------------------------------
			if(User.POSTID_D.equals(user.getPostId()) || User.POSTID_E.equals(user.getPostId())){
//				//校验是否具有审阅权限
				log.debug("当前用户" + empId + "不具备审阅他人日志的权限");
				message = new Message(Message.STATE_one, NOT_CAN_REVIEW_OTHERS);
			}
			else if(PostUtils.CompareBL(user.getPostId(), nowSearchPost) < 0){
				log.debug("当前用户" + empId + "不能审阅上级日志");
				message = new Message(Message.STATE_one, NOT_CAN_REVIEW_HIHGER.replace("LEVEL", user.getPostId()));
			} 
			else {
//				page = workConService.findWorkConViewListOfDow(empId, pageNo, pageSize, searchArea, searchPost, searchEmp, empId, workConType);
//				if(workConType != null && workConType.equals("3")){
//					page = workConService.findWorkConMarketViewListOfDow(empId,empId,pageNo,pageSize,workConType);
//				}else{
				
				log.info("用户不是普通员工,可以查看下级员工日志");
				log.info("empId:"+empId+"---"+ "pageNo:"+pageNo+"---"+ "pageSize:"+pageSize+"---"+ "searchArea:"+searchArea+"---"+ "searchPost:"+searchPost+"---"+ "searchEmp:"+searchEmp+"---"+"empId:"+ empId+"---"+ "workConType:"+workConType);
				log.info("isSearch:"+isSearch);
//				if(isSearch != null && isSearch.equals("1") && searchPost != null && !searchPost.equals("")){
//					page = workConService.findWorkConViewListOfSearch(empId, pageNo, pageSize, searchArea, searchPost, searchEmp, empId, workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
//				}else{
					page = workConService.findWorkConViewListOfDow(empId, pageNo, pageSize, searchArea, searchPost, searchEmp, empId, workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
//				}
//				}
				message = new Message(Message.STATE_200, "成功", page);
			}
		}
		//运营管理日志
		else if(Keys.WORK_CONTENT_RUNNING.equals(workConType)){
			//校验是否具有运营管理日志审阅权限
			if(isMarketReView(empId)){
//				String canBeReviewUser=Config.getProperty(CANBEREVIEWUSER);
				//add by jianghaibo 2015-02-04  获取可以被审阅人员列表
				String canBeReviewUser = workConPowerService.findPowerUserByType(CANBEREVIEWUSER);
				
				page = workConService.findWorkConMarketViewListOfDow(empId,empId,pageNo,pageSize,workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
				
				message=new Message(Message.STATE_200,"",page);
			}else{
				log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
				message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
			}
			
		}
		//B类经理人不允许查看
		else if(Keys.WORK_CONTENT_MANAGER_B.equals(workConType)){
			String canBeReviewUser = groupPowerService.findByViewEmpId(user.getEmpId().trim());
			//没有在权限组配置权限
			if(canBeReviewUser==null){
				log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
				message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
				return message;
			}
			boolean flag = false;//用来判断该员工是否有全部权限
			//如果该用户配置的ALL权限，即可以访问所有的B类日志
			if(canBeReviewUser.contains("ALL")){
				flag = true;
				if(viewType.trim().toUpperCase().equals("BZ")){
					canBeReviewUser = userSoftService.getAllManagerEmpIdByViewType("B", "ZGS");
				}else if(viewType.trim().toUpperCase().equals("BF")){
					canBeReviewUser = userSoftService.getAllManagerEmpIdByViewType("B", "FGS");
				}else{
					canBeReviewUser = "";
				}
			}
			//如果以上都没有，则按照查询到的用户去访问,则不做修改
			else{
				if(viewType.trim().toUpperCase().equals("BZ")){
					canBeReviewUser = groupPowerService.findByViewEmpIdAndViewTypeAndPostId(user.getEmpId().trim(), "ZGS","B"); //ZGS 总公司
				}else if(viewType.trim().toUpperCase().equals("BF")){
					canBeReviewUser = groupPowerService.findByViewEmpIdAndViewTypeAndPostId(user.getEmpId().trim(), "FGS","B"); //FGS 总公司
				}else{
					canBeReviewUser = "";
				}
			}
			
			if(canBeReviewUser==null||canBeReviewUser.trim().length()==0){
				if(flag){//具有全部审阅权限
					page = new Page<WorkConResult>();
					message=new Message(Message.STATE_200,"",page);
					return message;
				}else{
					log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
					message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
					return message;
				}
			}
			page = workConService.findWorkConViewList(canBeReviewUser, pageNo, pageSize,workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
			message=new Message(Message.STATE_200,"",page);
			
		}
		//基金会日志，需要查询T_ZZ_EMP_POWER_INFO表，查询该日志类型具有审阅权限的人，判断是否有权限审阅，如果有权限审阅，则查询该日志类型具有写权限的所有人的日志。
		else if(Keys.WORK_CONTENT_FOUNDATION.equals(workConType)){
			//判断是否具有审阅权限
			List<EmpPower> reviewEmpList = empPowerService.getEmpPowerList(empId, "R", Keys.WORK_CONTENT_FOUNDATION);
			//不具有审阅权限
			if(reviewEmpList==null||reviewEmpList.size()==0){
				log.debug("当前用户"+empId+"不具备审阅他人日志的权限");
				message=new Message(Message.STATE_one,NOT_CAN_REVIEW_OTHERS);
				return message;
			}
			//具有审阅权限，则查询该日志类型下所有具有写权限的员工列表
			List<EmpPower> writeEmpList = empPowerService.getEmpPowerList(null, "W", Keys.WORK_CONTENT_FOUNDATION);
			String canBeReviewUser = "";
			for(EmpPower e : writeEmpList){
				if(e.getEmpId().trim().equals(empId)){
					continue;//避免审阅自己写的日志
				}
				canBeReviewUser += e.getEmpId() +"|";
			}
			page = workConService.findWorkConViewList(canBeReviewUser, pageNo, pageSize,workConType,searchEmpName,searchConState,searchConStartTime,searchConEndTime);
			message=new Message(Message.STATE_200,"",page);
		}
		return message;
	}
	
	/**
	 * 判断是否是分公司管理员
	 * @param user
	 * @return
	 */
	private boolean isBranchManager(User user) {
		Dept dept = userRoleService.getDept(user.getDept_id());
		if(dept.getDept_name() != null && dept.getDept_name().indexOf("总公司") != -1){
			return false;
		}
		ManagerEmp managerEmp = managerEmpService.findId(user.getEmpId());
		if(managerEmp != null){
			return true;
		}
		return false;
	}

	/**
	 * 查看他人日志内容（如果有审批权限，同时进行审批）
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/getWorkConById.do", method = RequestMethod.POST)
	@ResponseBody
	public Message getWorkConById(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = null;
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			if (StringUtils.isNullOrEmpty(conForm.getToWorkConId())) {
				return new Message(Message.STATE_one, "数据参数异常");
			}
			WorkCon con = workConService.get(Long.parseLong(conForm.getToWorkConId()));
			User user = userService.getUserInfo(empId);
			WorkConResult result = new WorkConResult();
			result.setWorkcon1(con.getWorkcon1().replaceAll("\n", "</br>"));
			result.setCreate_time(con.getCreate_time());
//			result.setReviewState(con.getReviewState());
			if(con.getReviewState() != null && con.getReviewState().equals("3")){
				result.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASCOMMENT);
			}else{
				result.setReviewState(con.getReviewState());
			}
			result.setLog_date(con.getLog_date());
			if (isCanShareOfHO(empId)) {
				result.setIsShare(con.getIsShare());
			} else {
				result.setIsShare("-1");//没有分享权限
			}
			System.out.println("ppp");
			//该日志员工是否已经被关注
			String careUsers = user.getSpecialCare();
			String isSpicialCare = Keys.WORK_CONTENT_ISSHARE_NO;
			if (careUsers != null && !"".equals(con.getEmpId()) && careUsers.indexOf(con.getEmpId()) != -1) {
				isSpicialCare = Keys.WORK_CONTENT_ISSHARE_YES;
			}
			result.setIsSpecialCare(isSpicialCare);

			message = new Message(Message.STATE_200, "", result);
			if (!StringUtils.isNullOrEmpty(conForm.getWorkConType()) && ("1".equals(conForm.getWorkConType()) || "3".equals(conForm.getWorkConType()) || "4".equals(conForm.getWorkConType()) || "5".equals(conForm.getWorkConType()))) {
				boolean isBackResult = true;
				/** 如果查看人是写日志者自己，直接返回结果 */
				if (empId.equals(con.getEmpId())) {
					//add by jianghaibo 2015-05-22  如果已经该日志已经被批注，则修改 “已批注”状态为“已审阅”状态
					if(con.getReviewState() != null && con.getReviewState().equals("3")){
						con.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASREVEWED);
						con.setLog_date(con.getLog_date().substring(0, 10));
						workConService.updateWorkCon(con);
					}
				}
				/**
				 * 如果查看的是别人的日志，校验是否有查看权限；如果有，进行校验是否有审阅权限，
				 *如果有：更新日志状态为 已审阅；否则直接返回查询结果
				 */
				else {
					User user2 = userService.getUserInfo(con.getEmpId());
					String canBeReviewManagerBUser = groupPowerService.findByViewEmpId(user.getEmpId());
					List<EmpPower> emps = empPowerService.getEmpPowerList(empId, "R", conForm.getWorkConType());
					//校验是否具有查看权限 或者 是否具有审阅被查看着的权限
					if (isCanView(empId) || user.getPostId().compareTo(user2.getPostId()) <= 0 || isMarketReView(empId)||canBeReviewManagerBUser!=null||(emps!=null&&emps.size()!=0)) {
						//校验是否具有审阅权限
						if (isCanReview(empId) || user.getPostId().compareTo(user2.getPostId()) == -1 || isMarketReView(empId)||canBeReviewManagerBUser!=null||(emps!=null&&emps.size()!=0)) {
							System.out.println("con.getReviewState()--------"+con.getReviewState());
							if (Keys.WORK_CONTENT_REVIEWSTATE_FORREVIEW.equals(con.getReviewState())) {
								//更新审阅状态
								con.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASREVEWED);
								con.setReviewEmpId(empId);
								con.setLog_date(con.getLog_date().substring(0, 10));
								workConService.updateWorkCon(con);
							}
						}
					} else {
						isBackResult = false;
						System.out.println("777");
						log.debug("当前用户" + empId + "不具备查阅他人日志的权限");
						message = new Message(Message.STATE_one, NOT_CAN_VIEW_OTHERS);
					}
				}

				if (isBackResult) {
					message = new Message(Message.STATE_200, "", result);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 是否拥有审阅权限
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanReview(String empId) {
		//		String str=Config.getProperty(CANREVIEWUSER);
		//		if(str.indexOf(empId) != -1 ){
		//			return true;
		//		}else{
		//			return false;
		//		}
		//add by jianghaibo 2015-02-04
		WorkConPower conPower = new WorkConPower();
		conPower.setEmpId(empId);
		conPower.setPowerType(CANREVIEWUSER);
		conPower = workConPowerService.findByExample(conPower);
		WorkConMarketPower marketPower = new WorkConMarketPower();
		marketPower.setEmpId(empId);
		List<WorkConMarketPower> findListByExample = workConMarketPowerService.findListByExample(marketPower);
		
		if (conPower != null || (findListByExample != null && findListByExample.size() > 0)) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 是否拥有审阅运营管理日志权限
	 * 
	 * @param empId
	 * @author jianghiabo 2015-06-10
	 * @return
	 */
	private boolean isMarketReView(String operator){
		
		WorkConMarketPower conPower = new WorkConMarketPower();
		conPower.setEmpId(operator);
		List<WorkConMarketPower> list = workConMarketPowerService.findListByExample(conPower );
		if(list != null && list.size() > 0){
			return true;
		}
		return false;
	}

	/**
	 * 是否拥有查看他人日志权限
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanView(String empId) {
		//		String str=Config.getProperty(CANVIEWUSER);
		//		if(str.indexOf(empId) != -1 ){
		//			return true;
		//		}else{
		//			return false;
		//		}
		//add by jianghaibo 2015-02-04
		WorkConPower conPower = new WorkConPower();
		conPower.setEmpId(empId);
		conPower.setPowerType(CANVIEWUSER);
		conPower = workConPowerService.findByExample(conPower);
		
		if (conPower != null) {
			log.info("用户具有权限");
			return true;
		} else {
			log.info("用户不具有权限");
			return false;
		}
	}

	/**
	 * 是否可被他人审阅
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanBeReview(String empId) {
		//		String str=Config.getProperty(CANBEREVIEWUSER);
		//		if(str.indexOf(empId) != -1 ){
		//			return true;
		//		}else{
		//			return false;
		//		}
		//add by jianghaibo 2015-02-04
		WorkConPower conPower = new WorkConPower();
		conPower.setEmpId(empId);
		conPower.setPowerType(CANBEREVIEWUSER);
		conPower = workConPowerService.findByExample(conPower);
		if (conPower != null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 总公司用户是否拥有查看分公司人员日志的权限
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanViewOfHO(String empId) {
		//		String str=Config.getProperty(CANVIEWUSEROfHO);
		//		if(str.indexOf(empId) != -1 ){
		//			return true;
		//		}else{
		//			return false;
		//		}
		//add by jianghaibo 2015-02-04
		WorkConPower conPower = new WorkConPower();
		conPower.setEmpId(empId);
		conPower.setPowerType(CANVIEWUSEROfHO);
		conPower = workConPowerService.findByExample(conPower);
		if (conPower != null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 总公司用户是否拥有评论分公司人员日志的权限
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanReViewOfHO(String empId) {
		//		String str=Config.getProperty(CANREVIEWUSEROfHO);
		//		if(str.indexOf(empId) != -1 ){
		//			return true;
		//		}else{
		//			return false;
		//		}
		//add by jianghaibo 2015-02-04
		WorkConPower conPower = new WorkConPower();
		conPower.setEmpId(empId);
		conPower.setPowerType(CANREVIEWUSEROfHO);
		conPower = workConPowerService.findByExample(conPower);
		if (conPower != null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 是否拥有分享他人日志的权限
	 * 
	 * @param empId
	 * @return
	 */
	private boolean isCanShareOfHO(String empId) {
		log.info("用户是S级的,可以查看所有分公司员工日志");
		User user = userService.getUserInfo(empId);//查询当前用户信息
		String postId = user.getPostId();//职级
		TempDept tempDept = tempDeptService.findTD(empId);//在临时职位表中是否有信息
		if(tempDept!= null && tempDept.getPostId()!= null){
			postId = tempDept.getPostId();
		}
		if (postId.equals("S")) {
			log.info("用户是S级的,可以查看所有分公司员工日志");
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 添加工作日志的评论
	 * 
	 * @param request
	 * @param response
	 * @param reviewForm
	 * @return
	 */
	@RequestMapping(value = "/addworkConReview.do", method = RequestMethod.POST)
	@ResponseBody
	public Message addworkConReview(HttpServletRequest request, HttpServletResponse response, WorkReviewForm reviewForm) {
		Message m = new Message(Message.STATE_200, "");
		try {
			String operator = super.getEmpId(request);
			log.debug("当前操作人：" + operator);
			log.debug("被评论的工作id：" + reviewForm.getToWorkConId());
			log.debug("被评论内容：" + reviewForm.getContent());
			String content = reviewForm.getContent();
			//校验评论的内容
			if (StringUtils.isNullOrEmpty(content)) {
				m = new Message(Message.STATE_one, "评论内容不能为空！");
			} else if (content.getBytes("UTF-8").length > 300) {
				m = new Message(Message.STATE_one, "评论内容字符过多，请确认！");
			} else {
				User user = userService.getUserInfo(operator);
				WorkCon con = workConService.get(Long.parseLong(reviewForm.getToWorkConId()));
				User user2 = userService.getUserInfo(con.getEmpId());
				String canBeReviewManagerBUser = groupPowerService.findByViewEmpId(user.getEmpId());
				//校验是否具有审阅权限(评论即为审阅)
				if (isCanReview(operator) || PostUtils.CompareBL(user.getPostId(), user2.getPostId()) > 0 || isCanReViewOfHO(operator) || isMarketReView(operator)||canBeReviewManagerBUser!=null) {
					if (Keys.WORK_CONTENT_REVIEWSTATE_FORREVIEW.equals(con.getReviewState())) {
						//更新审阅状态
//						con.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASREVEWED);
						//update by jianghaibo 2015-05-22 当评论内容不为空时标记为已批注状态
						con.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASCOMMENT);
						con.setReviewEmpId(operator);
						con.setLog_date(con.getLog_date().substring(0, 10));
						workConService.updateWorkCon(con);
					}
					//add by jianghaibo 2015-05-22  对已审阅过的日志 再次评论 则更新状态为 “已批注”
					else if (Keys.WORK_CONTENT_REVIEWSTATE_HASREVEWED.equals(con.getReviewState())){
						con.setReviewState(Keys.WORK_CONTENT_REVIEWSTATE_HASCOMMENT);
						con.setReviewEmpId(operator);
						con.setLog_date(con.getLog_date().substring(0, 10));
						workConService.updateWorkCon(con);
					}

					WorkConCom com = new WorkConCom();
					com.setComEmpId(operator);
					com.setWorkConId(reviewForm.getToWorkConId());
					com.setComCon(reviewForm.getContent());
					workConComService.add(com);
				} else {
					m = new Message(Message.STATE_one, "对不起，您没有评论权限！");
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
			m = new Message(Message.STATE_one, "服务器异常");
			log.debug(m.toString());
		}
		return m;
	}

	/**
	 * 工作日志评论列表
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/workReviewList.do", method = RequestMethod.POST)
	@ResponseBody
	public Message workReviewList(HttpServletRequest request, HttpServletResponse response, WorkReviewForm form) {
		Message message = null;
		try {
			String id = form.getToWorkConId();
			if (StringUtils.isNullOrEmpty(id)) {
				message = new Message(Message.STATE_one, "标识符异常");
			} else {
				List<WorkConComResult> list = workConComService.findWorkReviewListOfTop10(id);
				message = new Message(Message.STATE_200, "", list);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 添加特别关心
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/addSpecialCare.do", method = RequestMethod.POST)
	@ResponseBody
	public Message addSpecialCare(HttpServletRequest request, HttpServletResponse response, WorkReviewForm form) {
		Message message = null;
		message = specialCare(request, form, true);
		return message;
	}

	/**
	 * 取消特别关心
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/revomeSpecialCare.do", method = RequestMethod.POST)
	@ResponseBody
	public Message revomeSpecialCare(HttpServletRequest request, HttpServletResponse response, WorkReviewForm form) {
		Message message = null;
		message = specialCare(request, form, false);
		return message;
	}

	private Message specialCare(HttpServletRequest request, WorkReviewForm form, boolean isCare) {
		Message message;
		try {
			String operator = super.getEmpId(request);
			String id = form.getToWorkConId();
			log.debug("当前操作人：" + operator);
			log.debug("被查看的工作日志id：" + id);
			WorkCon con = workConService.get(Long.parseLong(id));
			log.debug("被查看的工作日志的员工：" + con.getEmpId());

			if (StringUtils.isNullOrEmpty(id)) {
				message = new Message(Message.STATE_one, "标识符异常");
			} else {
				userService.specialCare(isCare, operator, con.getEmpId());
				message = new Message(Message.STATE_200, "取消特别关注成功");
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 工作日志分享
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/addWorkConShare.do", method = RequestMethod.POST)
	@ResponseBody
	public Message addWorkConShare(HttpServletRequest request, HttpServletResponse response, WorkReviewForm form) {
		Message message = workConShare(form, true, request);
		return message;
	}

	private Message workConShare(WorkReviewForm form, boolean isShare, HttpServletRequest request) {
		Message message = null;
		try {
			String operator = super.getEmpId(request);

			String id = form.getToWorkConId();
			log.debug("被查看的工作日志id：" + id);

			if (StringUtils.isNullOrEmpty(id)) {
				message = new Message(Message.STATE_one, "标识符异常");
			} else {
				workConService.workConShare(id, isShare);
				//update by jianghaibo 能看到日志即能分享日志
				if (isCanShareOfHO(operator)) {
					message = new Message(Message.STATE_200, "");
				} else {
					message = new Message(Message.STATE_one, "对不起，您没有分享权限！");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 取消日志分享
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/removeWorkConShare.do", method = RequestMethod.POST)
	@ResponseBody
	public Message removeWorkConShare(HttpServletRequest request, HttpServletResponse response, WorkReviewForm form) {
		Message message = workConShare(form, false, request);
		return message;
	}

	/**
	 * 工作日志分享列表
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/workConShareList.do", method = RequestMethod.POST)
	@ResponseBody
	public Message workConShareList(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = null;
		Page<WorkConResult> page;
		String workConType = conForm.getWorkConType();
		log.debug("请求日志类型：" + workConType);
		try {
			int pageNo = conForm.getPageNo() == 0 ? 1 : conForm.getPageNo();
			int pageSize = conForm.getPageSize() == 0 ? 10 : conForm.getPageSize();
			page = workConService.findWorkShareList(workConType, pageNo, pageSize);
			message = new Message(Message.STATE_200, "", page);
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 特别关心列表
	 * 
	 * @param request
	 * @param response
	 * @param statForm
	 * @return
	 */
	@RequestMapping(value = "/WCSpecialCareList.do", method = RequestMethod.POST)
	@ResponseBody
	public Message WCSpecialCareList(HttpServletRequest request, HttpServletResponse response, WorkConForm conForm) {
		Message message = null;
		Page<WorkConResult> page;
		String workConType = conForm.getWorkConType();
		log.debug("请求日志类型：" + workConType);
		try {
			String operator = super.getEmpId(request);
			int pageNo = conForm.getPageNo() == 0 ? 1 : conForm.getPageNo();
			int pageSize = conForm.getPageSize() == 0 ? 10 : conForm.getPageSize();
			page = workConService.WCSpecialCareList(operator, workConType, pageNo, pageSize);
			message = new Message(Message.STATE_200, "", page);
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	/**
	 * 是否是一把手日志人员
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/isNcPerson.do", method = RequestMethod.POST)
	@ResponseBody
	public Message isNcPerson(HttpServletRequest request, HttpServletResponse response) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			if (isCanReview(empId) || isCanReview(empId) || isCanBeReview(empId)) {

			} else {
				log.debug("当前用户" + empId + "不是一把手日志人员");
				message = new Message(Message.STATE_one, NOT_NC_PERSON);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}
	/**
	 * 获取员工职级及部门权限
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getUserPost.do", method = RequestMethod.GET)
	@ResponseBody
	public Message getUserPost(HttpServletRequest request, HttpServletResponse response) {
		Message message = null;
		UserModel userModel = new UserModel();
		try {
			String empId = super.getEmpId(request);
			User user = userService.getUserInfo(empId);
			Dept dept = null;
			TempDept tempDept = tempDeptService.findTD(empId);//在临时职位表中是否有信息
			if(isBranchManager(user)){
				userModel.setPostid(User.POSTID_A);
			}else{
				if(tempDept != null && tempDept.getPostId() != null){
					userModel.setPostid(tempDept.getPostId());;
				}else{
					userModel.setPostid(user.getPostId());
				}
			}
			
			if (tempDept != null && tempDept.getDept_id()!= null) {//在临时职位保重是否有职位信息
				dept = userRoleService.getDept(tempDept.getDept_id());
			}else{
				dept = userRoleService.getDept(user.getDept_id());
			}
			userModel.setDept_name(dept.getDept_name());;
			message = new Message(Message.STATE_200, "", userModel);
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}
	
	/**
	 * 判断是否是分公司管理员
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/isBranchManager.do", method = RequestMethod.POST)
	@ResponseBody
	public Message isBranchManager(HttpServletRequest request, HttpServletResponse response) {
		Message message = new Message(Message.STATE_200);
		try {
			String empId = super.getEmpId(request);
			log.debug("当前绑定人的empId：" + empId);
			User user = userService.getUserInfo(empId);
			if (isBranchManager(user) ) {
				message = new Message(Message.STATE_200,BRANCH_MANAGER_NOT_CAN_COMMENT);
			} else {
				log.debug("当前用户" + empId + "不是分公司管理员");
				message = new Message(Message.STATE_one);
			}
		} catch (Exception e) {
			e.printStackTrace();
			message = new Message(Message.STATE_one, "服务器异常");
			log.debug(message.toString());
		}
		return message;
	}

	public static void main(String[] adsf) {
		String createTime = "2015-09-25 11:34:53".substring(0, 10);
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, -1);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		//String nowTime=sdf.format(c.getTime());
		//System.out.println(createTime+"==="+nowTime);
		//System.out.println(createTime.compareTo(nowTime));

		String empids = "867031919|867013557|867015334|86000645|86000111|86000650|86000662|867019975|86000150|86410037|86000441|86000106|86000133|86000865|86000651|86000606|86000586|86000624|86000631|867017255|86360028|86000660|86000680|86000851|86000572|86000647|86320067|867010735";
		//86000865|86000851
		//System.out.println("---------"+empids.indexOf("86000865"));

		/*
		 * String searchArea="浙江分公司|分公司负责人";
		 * String searchPost ="A";
		 * if(searchPost.equals("A") && searchArea.indexOf("分公司负责人") > 0){
		 * int indexend = searchArea.indexOf("分公司负责人");
		 * searchArea = searchArea.substring(0,indexend-1);
		 * 
		 * }
		 */
		String aa = "'" + User.POSTID_S + "','" +User.POSTID_A + "','" +User.POSTID_B + "','" + User.POSTID_C + "','"+User.POSTID_D+"','" + User.POSTID_E + "'";
//		System.out.println(aa);
		String bb = "分公司协管责任人";
		System.out.println(bb.substring(0, bb.indexOf("责任人")));
	}
	
	

}
